// pages/user_center/driver/account_info/account_info.js
Page({
  data:{},
  onLoad:function(options){
      // 页面初始化 options为页面跳转所带来的参数
      var json = wx.getStorageSync('userInfo');
      this.setData({
          userInfo:json
      });

      var userType1 = wx.getStorageSync('userType');

      if(userType1 && userType1 != 5){
          var endTime = json.EfTime;

          var days = getDateDiff(endTime);
          console.log('days',days);
          if(days < 180 && days >=90){
              this.setData({
                  account_status:'warning'
              });
          }else if(days < 90){
              this.setData({
                  account_status:'danger'
              });
          }else{
              this.setData({
                  account_status:'normal'
              });
          }
      }
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  
  //下拉加载
  onPullDownRefresh: function(){
      wx.showToast({
          title: '正在加载...',
          icon: 'loading',
          duration: 10000
      });
      var that = this;
      var username = wx.getStorageSync('username');
      var password = wx.getStorageSync('password');

      wx.request({
        url: 'https://www.lanshuicar.com/Server/LoginAPI.ashx',
        data: {
          Tel : username,
          password : password
        },
        method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
        // header: {}, // 设置请求的 header
        success: function(res){
          // success
          var code = res.data.code;
          if(code == 0){
              var json = res.data.data[0];
              wx.setStorageSync('userInfo',json);

              that.setData({
                  userInfo:json
              });
          }
        },
        fail: function() {
          // fail
        },
        complete: function() {
          // complete
          wx.stopPullDownRefresh();
          wx.hideToast();
        }
      })
  }
})

function getUserInfo(){

}

function getDateDiff(startDate){
    var startTime = new Date(
      Date.parse(startDate.replace(/-/g,   "/"))).getTime();  

    var endTime = new Date().getTime(); 

    var dates = (startTime - endTime)/(1000*60*60*24);     
    return  dates;
}